package cn.service;

import cn.constant.Constants;
import cn.dao.DistrictDao;
import cn.dao.impl.DistrictDaoImpl;
import cn.entity.District;

import java.util.List;

/**
 * @author yale
 * @create 2017/10/9
 * @version 0.1
 */
public class DistrictService {
    DistrictDao dao = new DistrictDaoImpl();
    //数据访问   业务逻辑层
    public List<District> findAll(){

        List<District> list = dao.findByAll();
        if (null == list) {
            return null;
        }else{
            Constants.MESSAGE = "获取数据成功";
            return list;
        }
    }
    //新增
    public void add(int id){

    }
    //删除
    public void delete(int id){
        District district = new District();
        district.setId(id);
        int count = dao.delete(district);
        if (count > 0) {
            Constants.MESSAGE = "删除成功";
        }else {
            Constants.MESSAGE = "删除失败";
        }
    }
    //修改
    public void update(District dis){
        int count = dao.update(dis);
        if (count > 0) {
            Constants.MESSAGE = "修改成功";
        }
        else {
            Constants.MESSAGE ="修改失败";
        }
    }
    //根据ID查找该使用用户的信息
    public District findById(int id){
        District district = dao.findById(id);
        if (null == district) {
            Constants.MESSAGE = "没有该数据";
            return null;
        }
        return district;
    }
}
